/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package API;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author mrbao
 */
public class CheckBox extends Item {

    private boolean isCheck;
    private Image iconCheck;
    private Image iconUnCheck;
    private int max;

    public CheckBox(String text, int x, int y) {
        this.text = text;
        this.x = x + 2;
        this.y = y + 2;
        try {
            iconCheck = Image.createImage("/Icon/check.png");
            iconUnCheck = Image.createImage("/Icon/uncheck.png");
            max = font.getHeight() > iconCheck.getHeight() ? font.getHeight() : iconCheck.getHeight();
        } catch (Exception e) {
        }
    }

    public boolean isIsCheck() {
        return isCheck;
    }

    public void setIsCheck(boolean isCheck) {
        this.isCheck = isCheck;
    }

    public void Paint(Graphics g) {
        if (isCheck) {
            g.drawImage(iconCheck, x, y + (max - iconCheck.getHeight()) / 2, 0);
        } else {
            g.drawImage(iconUnCheck, x, y, 0);
        }
        g.setFont(font);
        g.setColor(0);
        if (isSelect) {
            g.drawRoundRect(x - 2, y - 2, font.stringWidth(text) + 5 + iconCheck.getWidth(), max + 3, cornerRadius, cornerRadius);
        }
        g.drawString(text, x + iconCheck.getWidth() + 2, y + (max - font.getHeight()) / 2 + 1, 0);
    }

    public int getHeight() {
        return max + 3;
    }

    public void KeyPress(int gameCode) {
        if (gameCode == Canvas.FIRE) {
            isCheck = !isCheck;
        }
    }
}
